package cn.assumejson.springframework.aop.framework.adapter;

import cn.assumejson.springframework.aop.MethodAroundAdvice;
import cn.assumejson.springframework.aop.MethodBeforeAdvice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 环绕通知
 *
 * @author gang.Li
 * @version 1.0
 * @since 1.0 2021/12/10 16:49
 */
public class MethodAroundAdviceInterceptor implements MethodInterceptor {

    private MethodAroundAdvice advice;

    public MethodAroundAdviceInterceptor(MethodAroundAdvice advice) {
        this.advice = advice;
    }

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        this.advice.around(methodInvocation.getMethod(), methodInvocation.getArguments(), methodInvocation.getThis());
        return methodInvocation.proceed();
    }
}
